# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-tls
_pkgname=tls
pkgver=0.15.3
pkgrel=4
pkgdesc="Transport Layer Security purely in OCaml"
url="https://github.com/mirleft/ocaml-tls"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-2-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-cstruct-dev
	ocaml-domain-name-dev
	ocaml-fmt-dev
	ocaml-hkdf-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lwt-dev
	ocaml-mirage-crypto-dev
	ocaml-mirage-clock-dev
	ocaml-mirage-flow-dev
	ocaml-mirage-kv-dev
	ocaml-ppx_sexp_conv-dev
	ocaml-ptime-dev
	ocaml-sexplib-dev
	ocaml-x509-dev
	"
makedepends="$depends_dev dune ocaml"
checkdepends="
	ocaml-alcotest-dev
	ocaml-cmdliner-dev
	ocaml-cstruct-unix-dev
	ocaml-ounit-dev
	ocaml-randomconv-dev
	"
options="!check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirleft/ocaml-tls/releases/download/v$pkgver/tls-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build -p tls,tls-mirage --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit \
		tls tls-mirage
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
371b85c6afebeda0fcc8cc5252e3333d9c3ef3a6bdbee160bb194e2a5928fd537c811c6eec729f16852070944e627257d44c97142a259d00d0db66956a95df49  ocaml-tls-0.15.3.tar.bz2
"
